package com.ming.closeto.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.ming.closeto.R;
import com.ming.closeto.utils.GlideUtils;
import com.ming.closeto.utils.LogUtils;

import java.util.List;

public class GalleryAdapter extends BaseAdapter {

    private Context mContext;
//    private LayoutInflater inflater;
    private List<String> mList;

    public GalleryAdapter(Context mContext, List<String> mList) {
        this.mContext = mContext;
        this.mList = mList;
        //inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
//        ViewHolder viewHolder = null;
//
//        if (convertView == null) {
//            viewHolder = new ViewHolder();
//            convertView = inflater.inflate(R.layout.layout_gallery_item, null);
//            viewHolder.iv_img = convertView.findViewById(R.id.iv_img);
//            convertView.setTag(viewHolder);
//        } else {
//            viewHolder = (ViewHolder) convertView.getTag();
//        }
//        String url = mList.get(position);
//        if (!TextUtils.isEmpty(url)) {
//            LogUtils.e("-----------------------" + url);
//            GlideUtils.loadImageviewCenterCrop(mContext, url, viewHolder.iv_img);
//        } else {
//            viewHolder.iv_img.setBackgroundResource(R.mipmap.ic_launcher);
//        }
//
//        return convertView;
        ImageView imageView = new ImageView(mContext);
        GlideUtils.loadImageviewCenterCrop(mContext, mList.get(position), imageView);
        // 动态设置全屏
        imageView.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT));
        return imageView;
    }

//    class ViewHolder {
//        private ImageView iv_img;
//    }
}
